﻿@inherits RazorFunction

@functions {
    public override string FunctionDescription
    {
        get { return "A page block which shows an image and text"; }
    }

    [FunctionParameter(Label = "Image", Help = "The major image component for this block.")]
    public DataReference<IImageFile> Image { get; set; }

    [FunctionParameter(Label = "Text", Help = "The text for this block.")]
    public XhtmlDocument Text { get; set; }

    [FunctionParameter(Label = "Image position", Help = "Where the image should be shown", DefaultValue = "Left", WidgetFactoryMethod = "GetImagePositionWidget")]
    public string ImagePosition { get; set; }

    public static WidgetFunctionProvider GetImagePositionWidget()
    {
        Expression<Func<object>> expression = () => GetImagePositionWidgetOptions();
        var method = (expression.Body as MethodCallExpression).Method;

        return StandardWidgetFunctions.DropDownList(method.DeclaringType, method.Name, false, false);
    }

    public static string[] GetImagePositionWidgetOptions()
    {
        return new[] { "Left", "Right" };
    }
}

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>
    <div class="page-block page-block-image-and-text">
        <div class="container">
            <div class="row">
                @if (ImagePosition == "Left")
                {
                    <div class="col-xs-12 col-sm-6 page-block-image">
                        <img alt="@Image.Data.Title" src="@Html.C1().MediaUrl(Image.Data)" />
                    </div>
                }
                <div class="col-xs-12 col-sm-6 page-block-text">
                    <div class="page-block-text-inner">
                        @Markup(Text)
                    </div>
                </div>
                @if (ImagePosition != "Left")
                {
                    <div class="col-xs-12 col-sm-6 page-block-image">
                        <img alt="@Image.Data.Title" src="@Html.C1().MediaUrl(Image.Data)" />
                    </div>
                }
            </div>
        </div>
    </div>

</body>
</html>
